<template>
	<div class="qf-login blue-page" @keyup.13="login">
        <a href="#" id="loginLogo"></a>
        <div class="container">
            <div class="qf-login-broadcast fl">
                <div class="broadcast-txt">
                    <p>助力新房代理公司整合下游合作伙伴</p>
                    <p>将报备确认、佣金结算等渠道业务</p>
					<p>全面系统化运营</p>
                </div>
            </div>
            <div class="qf-login-form fl">
                <div class="qf-login-title">巧渠道</div>
                <div class="login-form">
                    <div class="qf-input-box">
                        <div class="input-icon fl">
                            <div class="input-icon-img1"></div>
                        </div>
                        <div class="qf-input fl">
                            <input type="text" name="phone" v-model="loginData.phone" placeholder="请输入手机号">
                        </div>
                    </div>
                    <div class="qf-input-box">
                        <div class="input-icon fl">
                            <div class="input-icon-img2"></div>
                        </div>
                        <div class="qf-input fl">
                            <input type="password" name="password" v-model="loginData.password" placeholder="请输入密码">
                        </div>
                    </div>
                </div>
                <a class="btn-login btn-login-orange" @click="login">登&nbsp;&nbsp;录</a>
                <a href="javascript:void(0)" @click="toResetPwd" style="color:#666;float: right;padding-top: 20px;padding-right: 50px;text-decoration-line: underline;">忘记密码</a>
                <div class="qf-login-footer">上海巧房信息科技有限公司</div>
            </div>
        </div>
    </div>
</template>

<script>
	export default {
		data() {
				return {
					logoInfo: {
						logoType: '5'
					},
					loginData:{
						 phone:'',
						 password:'',
						 wxOpenId: '',
						 cooCompanyId:'',
						 domain:''
					},
					companyList:[]
				}
			},
			mounted: function() {
				this.initPage();
				this.getCompanyLogo();
			},
			methods: {
				getCompanyLogo: function () {
	                var _self = this;
	                var url = _self.utilHelper.apiUrl + "/api/getLogo";
					var body = {};
					body.params = _self.logoInfo;
	                _self.$http.post(url, body).then((response) => {
	                    var data = response.body.resData;
	                    if (data && data.result=='1') {
	                        $("#loginLogo").addClass("logo");
	                        $("#loginLogo").css("backgroundImage","url("+data.logoUrl+")");
	                    }else{
	                    	$("#loginLogo").addClass("logo");
	                    }
	                })
	            },
				initPage() {
					// 设置高度
					var oMain = $(".sign-content");
					var oHeight = $(window).height();
					if(oHeight > 973) {
						oMain.css("height", "973px");
					} else if(oHeight < 800) {
						oMain.css("height", "800px");
					} else {
						oMain.css("height", oHeight + "px");
					}
				},
				login() {
					var _self=this;
					if(_self.vaild()){
						var url = _self.utilHelper.apiUrl + "/api/login";
						var body = {};
						body.params = _self.loginData;
				   	 	_self.$http.post(url, body).then((response) => {
								var resData = response.body.resData;
					   			var result=resData.result;
                                var errorMsg = resData.errorMsg;
                                var resultMsg = resData.resultMsg;
                                var errorCode = resData.errorCode;
			    		    	if(result=="1"){
									window.localStorage.setItem("1_isLogin", true);
									window.localStorage.setItem("1_userId", resData.id);
									window.localStorage.setItem("1_userName", resData.accountName);
									window.localStorage.setItem("1_userPhone", resData.phone);
									window.localStorage.setItem("1_accountType",resData.accountType);
									window.localStorage.setItem("1_loginType",resData.loginType);
									window.localStorage.setItem("1_companyUuid", this.getQueryString('companyUuid'))
									_self.$store.dispatch('getMenuList').then((firstHref)=>{
										_self.$router.replace({
										    path: firstHref
									    })
									})									
			    		    	}else{
			    		    	    if(errorCode == "1000"){
                                        layer.msg(errorMsg, {
                                            time: 1000
                                        });
                                    }else{
                                        layer.msg(resultMsg, {
                                            time: 1000
                                        });
                                    }

			    		    	}
					  		}, (response) => {
					  	});
					}
				},
				getQueryString (name) {
					var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
					var r = window.location.search.substr(1).match(reg);

					if (r != null) {
						return unescape(r[2])
					};
					return null
				},
				toResetPwd(){
                    this.$router.push({path:'/forgetPassword'});
                },
				vaild:function(){
					var _self = this;
					if(!_self.loginData.phone){
						layer.msg("请输入登录帐号",{
							time: 2000
						});
						return false;
					}
					if(!_self.loginData.password){
						layer.msg("请输入登录密码",{
							time: 2000
						});
						return false;
					}
					return true;
				},
				//获取合作商
				loadCompany(){
					var _self = this;
					var params = {};
					var url = _self.utilHelper.apiUrl + "/api/loadCompany.do";
				   	_self.$http.post(url, params).then((response) => {	
				   	 	var data = response.body;
				   	 	_self.companyList = data
				   	});
				}
			}
	}
</script>
<style>
	#app{height: 100%;}
	.row-select{height: 40px;line-height: 40px;width: 170px;background-color: transparent;padding-left: 8px;border:none;}
</style>